package com.example.thread;

import java.util.concurrent.locks.ReentrantLock;

public class Main {

    public static void main(String[] args) {

        ReentrantLock reentrantLock = new ReentrantLock();
        ReentrantLock reentrantLock1 = new ReentrantLock();

        new Thread(() -> {
            reentrantLock.lock();
            System.out.println("线程1获得第一个锁");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            reentrantLock1.lock();
            System.out.println("线程1获得第二个锁");
        }).start();

        new Thread(()->{
            reentrantLock1.lock();
            System.out.println("线程2获得第二个锁");
            reentrantLock.lock();
            System.out.println("线程2获得第一个锁");
        }).start();

    }

}
